package com.github.netty.listener;

import com.github.netty.context.NettyApplicationContext;
import com.github.netty.server.NettyServer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.util.ObjectUtils;

/**
 * @author ArchieSean
 * @description 用于监听ioc容器准备完成
 * @date 2024-08-14
 */
public class NettyApplicationListener implements ApplicationListener<ApplicationReadyEvent> {

    private static final Log logger = LogFactory.getLog(NettyApplicationListener.class);
    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        logger.info("--IOC容器已就绪，启动netty服务开始--");
        NettyServer nettyServer = NettyApplicationContext.getBean(NettyServer.class);
        if(!ObjectUtils.isEmpty(nettyServer)){
            nettyServer.startNettyServer();
        }
        logger.info("--IOC容器就绪，netty服务启动完成--");
    }



}
